Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing local macro across do file | Arguments needed?

    I need to do repeated Cox analysis and have a set of codes to grab median and overall survival and several numbers that keep repeating over in a putdocx file for different binary variables with 1 being the worse outcome. I would like shorten the code by saving all options related to the numbers stored in a separate do file.

    In the result analysis do file I have:

    The main script for the results below in the do file:
    Code:
    local x myvar
    
     do "C:\Users\Vijayalakshmi\Dropbox\Girish Files\Stata practice\survmasf.do"
    
    putdocx text (" Patients lacking the myvar signature (n = `n0' [`p0'%]) had significantly superior median survival (`med0' months vs. `med1' months) and OS24 (`ms0_val' (vs. `ms1_val') compared those carrying the signature (HR= `b'; 95% CI= [`l'-`u'], p = `p') comprising (n = `n1' [`p1'%])")
    drop ms0* ms1* _rc* _d_* tt med*
    The script of all options for the numbers in this nested survmasf.do file:
    Code:
    stcox ib0.`x' ib0.age70
    matrix list r(table)
    local b = round(r(table)[1,2], 0.01)
    local l = round(r(table)[5,2], 0.01)
    local u = round(r(table)[6,2], 0.01)
    local p = round(r(table)[4,2], 0.0001)
    local n = e(N)
    ****** Numbers in each group************
    estpost tab `x'
    mat list e(pct)
    local p0 = string(round(e(pct)[1,1], 0.1))
    local p1 = string(round(e(pct)[1,2], 0.1))
    mat list e(b)
    local n0 = e(b)[1,1]
    local n1 = e(b)[1,2]
    
    *Get Median and 24mo OS after adjusted analysis
    range tt 1 24 24
    qui stpm2 i.`x' i.age70, df(4) eform scale(h)
    forval i=0/1{
    predict ms`i', meansurv ci timevar(tt) at(`x' `i')
    }
    
    *Median survival
    predict medsurv, centile(50)
    summ medsurv if `x'==0, detail
    local med0 = round(r(p50), 0.1)
    
    summ medsurv if `x'==1, detail
    local med1 = round(r(p50), 0.1)
    
    *OS24 
    local ms0_val = string(round(ms0[24] * 100, 0.1), "%9.1f") + "%"
    local ms1_val = string(round(ms1[24] * 100, 0.1), "%9.1f") + "%"
    The code hangs with this below

    Code:
    . stcox ib0.`x' ib0.age70
    ib0.age70 invalid name
    r(198);
    How do I make the nested do file read the local macro defined in the main do file?

  • #2
    See [U] 16.4.1 and its references. By your definition local macro x is local to your main program. The do file can accept arguments but they must be given with the do command and are mapped to its local macros 1, 2 and so forth.

    Comment


    • #3
      Nick Cox c
      ​​​​​​​1-- In STATA I have 500 data and the data name "delivery kit" For this data I have three forms one is the "enrollment form" the second form is the "follow-up form" and the third one is the "devilry form" and every enrolment against three followups and first follow-up done 7th day after enrollment and 2nd followup 14th days after enrollment and 3rd followup 28days after enrolment. Hence, I find that every enrollment against how many follow-ups and which day after enrolment, so what command will use in STATA?

      2- in STATA I have 500 data in this one variable is "date of last menstrual period" and the second variable is "date of outcome or date of delivery" to find the difference between the date of delivery and date of last menstrual period and generate new variable so what command will use in STATA

      Comment

      Working...
      X